package definite.Guide.Book.ToggleButton;

import java.awt.BorderLayout;
import java.awt.EventQueue;
import java.awt.GridLayout;

import javax.swing.AbstractButton;
import javax.swing.BorderFactory;
import javax.swing.ButtonGroup;
import javax.swing.JCheckBox;
import javax.swing.JCheckBoxMenuItem;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.JRadioButton;
import javax.swing.JRadioButtonMenuItem;
import javax.swing.JToggleButton;
import javax.swing.border.Border;

public class AButtonGroup {

	public static void main(String[] args) {
		Runnable run = new Runnable() {

			@Override
			public void run() {

				JFrame frame = new JFrame("Button Group");
				frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

				JPanel panel = new JPanel(new GridLayout(0, 1));
				Border border = BorderFactory.createTitledBorder("Example");
				panel.setBorder(border);

				
				// ButtonGroup object means that turning "on" one of those buttons 
				// and turns off all other buttons in the group. 

				ButtonGroup btnGroup = new ButtonGroup();
				AbstractButton abstract1 = new JToggleButton("Toggle Button");

				panel.add(abstract1);
				btnGroup.add(abstract1);

				AbstractButton abstract2 = new JRadioButton("Radio Button");
				panel.add(abstract2);
				btnGroup.add(abstract2);

				AbstractButton abstract3 = new JCheckBox("CheckBox");
				panel.add(abstract3);
				btnGroup.add(abstract3);

				AbstractButton abstract4 = new JRadioButtonMenuItem(
						"RadioButton Menu Item");
				panel.add(abstract4);
				btnGroup.add(abstract4);

				AbstractButton abstract5 = new JCheckBoxMenuItem(
						"CheckBox Menu Item");
				panel.add(abstract5);
				btnGroup.add(abstract5);

				frame.add(panel, BorderLayout.CENTER);
				frame.setLocationRelativeTo(null);
				frame.setSize(300, 200);
				frame.setVisible(true);

			}
		};

		EventQueue.invokeLater(run);
	}

}
